// dhcp_toolDlg.h : header file
//

#pragma once

#include <sys/timeb.h>
#include "config_file.h"
#include "afxwin.h"

// Cdhcp_toolDlg dialog
class Cdhcp_toolDlg : public CDialog
{
// Construction
public:
	Cdhcp_toolDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_DHCP_TOOL_DIALOG };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:
    UINT_PTR GetTimerHandle() const { return timer;}
    bool GetTimeout() {return timeout;}
    void SetTimeout(bool value) {timeout = value;}
    void SetTimerHandle(UINT_PTR hd) {timer = hd;}

    B_U32 GetLocalIp() const {return localIp;}
    B_U32 GetServerIp() const {return serverIp;}
    B_U32 GetInterval() const {return atoi(csInterval);}
    
    void ReleaseRes();	
    void ChangeControlStatus(bool defaultValue);
    void UpdateResult();
    
	afx_msg void OnBnClickedOk();
	
    volatile bool    recvExit;
    volatile bool    sendExit;
    
	B_U32   discoverCnt;
	B_U32   offerCnt;
	B_U32   requestCnt;
	B_U32   ackCnt;
	
private:
    void InitMember();
	void ResetValues();

    bool CheckInput();
    void InitServerSockAddr();
    void SaveMember();

    void WinSockStartUp();

	CString csLocalIp;
	CString szServerIp;
	CString csInterval;
	CString csTotalTime;

    volatile bool    timeout;    
	B_U32   localIp; //network order
	B_U32   serverIp;
	
	struct sockaddr_in sockaddrServer;
	
	CString csDiscover;	
	CString csOffer;
	CString csRequest;
	CString csAck;
	
	HANDLE	handleSendThread;
	HANDLE	handleRecvThread;
	DWORD	dwSendThreadID;
	DWORD	dwRecvThreadID;

	UINT_PTR timer;

	struct _timeb timeStart;
	struct _timeb timeEnd;
	
	afx_msg void OnBnClickedCancel();
private:
	CString csPerformance;
	afx_msg void OnBnClickedStop();
};
